package output;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Scanner;

import organization.Base;
import person.*;

public abstract class Console {
	ArrayList<String> consoleStr = new ArrayList<String>();

	public void getConsole() {
		System.out.println();
		System.out.println("Work with:");
		for (int i = 0; i < consoleStr.size(); i++) {
			System.out.println((i + 1) + ". " + consoleStr.get(i));
		}
		inputInConsole();
	}

	public void inputInConsole() {
	}

	PersonInfo AddPersonal() {
		Scanner scan = new Scanner(System.in);
		String firstName;
		String secndName;
		String placeOfBirth;
		int dayBirth;
		int monthBirth;
		int yearBirth;
		int curYear = Calendar.getInstance().get(Calendar.YEAR);
		
		
		System.out.println("Please enter Fist Name:");
		firstName = scan.next();
		System.out.println("Please enter Second Name:");
		secndName = scan.next();
		System.out.println("Please enter Place of Birth:");
		placeOfBirth = scan.next();
		System.out.println("Please enter Birth:");

		System.out.println("Day:");
		while (true) {
			if (scan.hasNextInt()) {
				dayBirth = scan.nextInt();
				break;
			} else {
				System.out.println("Should be numeric!");
				scan.next();
			}
		}
		System.out.println("Month:");
		while (true) {
			if (scan.hasNextInt()) {

				monthBirth = scan.nextInt();
				if (monthBirth > 0 & monthBirth <= 12) {
					break;
				} else {
					System.out.println("Incorrect month number!");
				}
			} else {
				System.out.println("Should be numeric!");
				scan.next();
			}
		}
		System.out.println("Year:");
		while (true) {
			if (scan.hasNextInt()) {
				yearBirth = scan.nextInt();
				if (yearBirth > (curYear-120) & yearBirth <= (curYear-10)){
				break;
				}else {
					System.out.println("Person should be not older than 120 and not junger than 10!");
				}
			} else {
				System.out.println("Should be numeric!");
				scan.next();
			}
		}
		PersonInfo person = new PersonInfo(firstName, secndName, placeOfBirth,
				dayBirth, monthBirth, yearBirth);
		if (Base.checkUniq(person)) {
			return person;
		} else {
			System.out
					.println("Person with this name and place of birth exists.\r\n Please enter \"y\" to add anyway or any to exit.");
			if (scan.next().equals("y")) {
				return person;
			} else {
				System.out.println("Operation rejected.");
				return null;
			}
		}
	}
}
